package service

import (
	"context"
	"fmt"
	__ "user-srv/basic/proto"
	"user-srv/handler/dao"
)

// 会员权益添加
func (s *Server) MemberBenefitAdd(_ context.Context, in *__.MemberBenefitAddReq) (*__.MemberBenefitAddResp, error) {
	if in.Name == "" || in.Types == 0 || in.Desc == "" {
		return nil, fmt.Errorf("参数错误")
	}

	benefit, err := dao.MemberBenefitAdd(in)
	if err != nil {
		return nil, fmt.Errorf(err.Error())
	}

	return &__.MemberBenefitAddResp{
		Id: benefit.Id,
	}, nil
}

// 会员权益展示
func (s *Server) MemberBenefitFind(_ context.Context, in *__.MemberBenefitFindReq) (*__.MemberBenefitFindResp, error) {
	benefit, err := dao.MemberBenefitFind(in)
	if err != nil {
		return nil, fmt.Errorf("查询失败")
	}

	return &__.MemberBenefitFindResp{
		List: benefit,
	}, nil
}

// 会员权益详情
func (s *Server) MemberBenefitDetail(_ context.Context, in *__.MemberBenefitDetailReq) (*__.MemberBenefitDetailResp, error) {
	benefit, err := dao.MemberBenefitDetail(in)
	if err != nil {
		return nil, fmt.Errorf(err.Error())
	}

	return &__.MemberBenefitDetailResp{
		Id:    benefit.Id,
		Name:  benefit.Name,
		Desc:  benefit.Desc,
		Types: uint64(benefit.Types),
	}, nil
}
